/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mudalov.rec.dao.hibernate.impl;

import com.mudalov.rec.dao.interfaces.HbnGenericDAO;
import com.mudalov.rec.dao.interfaces.ITeacherDAO;
import com.mudalov.rec.dao.model.user.Role;
import com.mudalov.rec.dao.model.user.Teacher;
import com.mudalov.rec.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author MU
 */
public class HbnTeacherDAO extends HbnGenericDAO<Teacher, Long> implements
		ITeacherDAO {

	public HbnTeacherDAO(SessionFactory sesssionFactory) {
		this.sessionFactory = sesssionFactory;
	}

	@Override
	protected Class<Teacher> getEntityClass() {
		return Teacher.class;
	}

    public Teacher getTeacher(String login, String password) {
        List<Criterion> criterions = new ArrayList<Criterion>();
        criterions.add(Restrictions.eq("password", password));
        criterions.add(Restrictions.eq("login", login));
        return findDetachedObjectByCriteria(criterions);
    }

    public List<Teacher> getTeachers(String fullName, String login, String mail) {
        List<Criterion> criterions = new ArrayList<Criterion>();
        if (!StringUtil.areEmpty(fullName)) {
            criterions.add(Restrictions.like("fullName", "%" + fullName + "%"));
        }
        if (!StringUtil.areEmpty(login)) {
            criterions.add(Restrictions.like("login", "%" + login + "%"));
        }
        if (!StringUtil.areEmpty(mail)) {
            criterions.add(Restrictions.like("mail", "%" + mail + "%"));
        }
        List<Teacher> result = findDetachedObjectsByCriteria(criterions);
        return result;
    }
}
